import requests
from bs4 import BeautifulSoup

# 设置请求头，伪装成浏览器访问
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}

# 萍乡学院官网URL
url = 'https://www.pxu.edu.cn'

# 发送GET请求获取网页内容
response = requests.get(url, headers=headers)

# 确保请求成功
if response.status_code == 200:
    # 设置正确的编码格式，防止乱码
    response.encoding = 'utf-8'  # 或者根据网页实际编码进行调整，如 'gbk'

    # 获取网页HTML内容
    html_content = response.text

    # 将HTML内容保存到本地文件
    with open(r'C:\Users\86178\Desktop\萍乡学院.html', 'w', encoding='utf-8') as f:
        f.write(html_content)

    print("页面已成功保存到 C:\\萍乡学院.html")
else:
    print(f"请求失败，状态码：{response.status_code}")